<?php 
/**
 * 
 */
 class SgpageController extends AuthController
 {	
 	private $_db;
	public function __init(){
		parent::__init();
		$this->_db = K('Sgpage') ;
	}

	Public function index(){
		$this->sgList = M('sgpage')->field(array('id','title'))->all();
		$this->display();
	}
	
	Public function add(){
		if(IS_POST){
			if($this->_db->addSgpage()){
				$this->success('添加成功','index');
			}else{
				$this->error('添加失败');
			}
		}else{
			$this->display();
		}
	}

	Public function edit(){
		$id = Q('id',0,'intval');
		if(empty($id)){
			$this->error('参数传递错误');
		}
		if(IS_POST){
			if($this->_db->editSgpage()){
				$this->success('修改成功','index');
			}else{
				$this->error('修改失败');
			}
		}else{
			$this->field = $this->_db->find($id);
			$this->display();
		}
	}

	public function del(){
		$id = Q('id',0,'intval');
		if(empty($id)){
			$this->error('参数传递错误');
		}
		if($this->_db->del($id)){
			$this->success('文章删除成功','index');
		}else{
			$this->error('文章删除失败');
		}
	}
 } ?>